<template>
  <div>
    <div class="topbig">
      <p class="cha">&emsp;&emsp;查询</p>
      <div class="sou">
        &emsp;&emsp;&emsp;&emsp;搜索&emsp;<el-input v-model="input" placeholder="输入菜品名称进行搜索" class="shuru" @blur="mohusousuo()"></el-input>
       </div>
    </div>
   
     <div class="main">
      <p class="caipin">&emsp;&emsp;折扣菜品</p>
     
    </div>
 
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="xuhao" label="序号"></el-table-column>
      <el-table-column prop="foodId" label="菜品编号"> </el-table-column>
      <el-table-column prop="foodName" label="菜品名称"> </el-table-column>
      <el-table-column prop="foodDiscoun" label="折扣"> </el-table-column>
      
    </el-table>

    
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import {findlikelimit,findDiscount} from "@/apis/ningsh/ningsh.js";
export default {
  data() {
    return {
      total:0,
      pageSize:5,
       input: '',
      currentPage: 1,
    tableData:[{}],
    };
  },
 
  mounted(){
     this.render()
  },
  methods: {
    render(){
        findDiscount().then((ok)=>{
              console.log(ok);
              this.tableDatab=ok.data.data
              this.tableData=ok.data.data.slice((this.currentPage-1)*this.pageSize,this.currentPage*this.pageSize)
              this.total=this.tableDatab.length
            })
    },
    mohusousuo(){
      //input模糊查询
        findlikelimit(this.input).then((ok)=>{
          console.log(ok);
          this.tableData=ok.data.data.records
         this.total=this.tableData.length
        })
    },
    handleSizeChange(val) {
      this.pageSize=val
      this.render()
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage=val
      this.render()

    },
  },
};
</script>

<style scoped>
.topbig {
  width: 100%;
  height: 145px;
  border: 1px solid #ccc;
}
.cha {
  display: flex;
  align-items: center;
  height: 45%;
  background-color: #ccc;
}
.sou {
  font-size: 10px;
  height: 55%;
  display: flex;
  align-items: center;
}
.shuru{
  width: 300px;
}
.main {
  margin-top: 10px;
  margin-bottom: 10px;
  background-color: #ccc;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.caipin {
  width: 100%;
  display: flex;
  align-items: center;
  height: 60px;
}

</style>